package com.rabbitmq.demos.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import com.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.utils.RabbitConfig;

/**
 * 向队列中发送100条消息
 */
public class NewTask {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        // 声明队列
        channel.queueDeclare(RabbitConfig.queue, true, false, false, null);
        for(int i=1;i<=20;i++){
            String message = String.join(" ", i+"_message.work");
            channel.basicPublish("", RabbitConfig.queue,  MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");
            Thread.sleep(i * 10);
        }
        channel.close();
        connection.close();
    }
}
